#include <bits/stdc++.h>

#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

template<class T> void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T> void chkmx(T &x, T y) { if (y > x) x = y; }

using namespace std;

const int maxn = 1000010;

struct number {
  ll k, b;
  number(ll x) { k = 0, b = x; }
  number(ll x, ll y) { k = x, b = y; }
  friend number operator+(number x, number y) {
    return number(x.k + y.k, x.b + y.b);
  }
};

int n, sz[maxn], c[maxn], tot, buc[maxn];
ll val[maxn], b[maxn], cost;
vector<int> a[maxn], id[maxn], lst[maxn];
vector<pair<ll, number>> delta;
vector<ll> ans;

ll calc(int d) {
  ll ans = 0;
  rep (i, 1, tot) buc[i] = 0;
  rep (i, 1, n) {
    rep (j, 0, sz[i] - 1) {
      if (j == sz[i] - 1 || a[i][j + 1] >= a[i][j] + d) ans += cost * (a[i][j] + d);
      if (j == 0 || a[i][j] >= a[i][j - 1] + d) ans -= cost * a[i][j];
    }
  }
  rep (i, 1, tot) {
    int cnt = 0;
    for (int x : lst[i]) cnt += (d <= x);
    ans += b[cnt];
  }
  return ans;
}

int main() {
  freopen("list.in", "r", stdin);
  freopen("list.out", "w", stdout);
  cin.tie(nullptr) -> ios::sync_with_stdio(false);
  cin >> n;
  rep (i, 1, n) {
    cin >> sz[i], a[i].resize(sz[i]), id[i].resize(sz[i]);
    for (int &x : a[i]) cin >> x, c[++tot] = x;
  }
  sort(c + 1, c + tot + 1), tot = unique(c + 1, c + tot + 1) - c - 1;
  rep (i, 1, n) {
    rep (j, 0, sz[i] - 1) id[i][j] = lower_bound(c + 1, c + tot + 1, a[i][j]) - c;
    rep (j, 0, sz[i] - 1) {
      if (j == 0) lst[id[i][j]].emplace_back(2e9);
      else lst[id[i][j]].emplace_back(a[i][j] - a[i][j - 1]);
    }
  }
  cin >> cost;
  rep (i, 1, n) cin >> b[i], b[i] *= i;
  rep (i, 1, n) {
    rep (j, 0, sz[i] - 1) {
      if (j == sz[i] - 1) {
        delta.emplace_back(1, number(cost, cost * a[i][j]));
      } else {
        delta.emplace_back(1, number(cost, cost * a[i][j]));
        delta.emplace_back(a[i][j + 1] - a[i][j] + 1, number(-cost, -cost * a[i][j]));
      }
      if (j == 0) {
        delta.emplace_back(1, number(-cost * a[i][j]));
      } else {
        delta.emplace_back(1, number(-cost * a[i][j]));
        delta.emplace_back(a[i][j] - a[i][j - 1] + 1, number(cost * a[i][j]));
      }
    }
  }
  rep (i, 1, tot) if (!lst[i].empty()) {
    sort(ALL(lst[i])), delta.emplace_back(1, number(0, b[SZ(lst[i])]));
    int cur = SZ(lst[i]);
    for (int l = 0, r; l < SZ(lst[i]); l = r + 1) {
      r = l;
      while (r + 1 < SZ(lst[i]) && lst[i][r + 1] == lst[i][l]) r++;
      delta.emplace_back(lst[i][l] + 1, b[cur - (r - l + 1)] - b[cur]);
      cur -= r - l + 1;
    }
  }
  delta.emplace_back(1, number(0)), delta.emplace_back(2e9, number(1e18));
  sort(ALL(delta), [&](auto x, auto y) { return x.fi < y.fi; });
  number sum(0);
  ll mn = 1e18;
  for (int l = 0, r; l < SZ(delta); l = r + 1) {
    r = l;
    while (r + 1 < SZ(delta) && delta[r + 1].fi == delta[l].fi) r++;
    rep (i, l, r) sum = sum + delta[i].se;
    if (delta[l].fi == 2e9) break;
    ll L = delta[l].fi, R = delta[r + 1].fi - 1;
    chkmn(mn, sum.k * L + sum.b);
  }
  sum = number(0);
  for (int l = 0, r; l < SZ(delta); l = r + 1) {
    r = l;
    while (r + 1 < SZ(delta) && delta[r + 1].fi == delta[l].fi) r++;
    rep (i, l, r) sum = sum + delta[i].se;
    if (delta[l].fi == 2e9) break;
    ll L = delta[l].fi, R = delta[r + 1].fi - 1;
    if (sum.k == 0 && sum.b == mn) {
      rep (i, L, R) ans.emplace_back(i);
    } else if (sum.k > 0 && sum.k * L + sum.b == mn) {
      ans.emplace_back(L);
    }
  }
  cout << mn << " " << SZ(ans) << '\n';
  for (ll x : ans) cout << x << " ";
  cout << '\n';
}